
ResAuditEdit = new Pearlsen.BaseEdit({
	formId:'auditForm',
	idProperty:'stepId',
	moduleName:'ResAudit',
	queryMethod:'getEntity',
	dataSetHandler:'ResAuditDataSetHandler',
	queryHandler:'ResAuditQueryHandler',
	saveMethod:'save',
	initFun:function(){
		this.applyId = this.getQueryString("applyId");
	},
	onchange:function(field,newValue,oldValue){
		var msg = "";
		if(newValue=="0"){
			msg ="不同意";
		}else{
			msg ="同意";
		}
		Ext.getCmp("auditOpinion").setValue(msg);
	},
	renderGrid:function(value,metaData,record,rowIndex,colIndex,store,view){
		var ret = '' ,memoryunit,storageunit,opsSeries;	
		var units =['MB','GB','TB'];
		var ops={XP_TPL:'Window XP',WIN7_TPL:'Window 7',LINUX_TPL:'LINUX'};
		opsSeries = record.data['opsSeries'];
		memoryunit = record.data['memoryunit'];
		storageunit = record.data['storageunit'];
		switch(colIndex){
			case 5:
				ret =ops[value];
				break;
			case 7:
				ret = value+units[memoryunit];
				break;
			case 8:
				ret = value +units[storageunit];
				break;
		}
		return ret;
	},
	fillHostForm:function(view,record,item,index,e,eOpts){
		var hostForm = Ext.getCmp("hostForm");
		hostForm.queryById("configId").setValue(record.data['configId']);
		hostForm.queryById("hostName").setValue(record.data['hostName']);
		hostForm.queryById("opsSeries").setValue(record.data['opsSeries']);
		hostForm.queryById("opsName").setValue(record.data['opsName']);
		hostForm.queryById("cups").setValue(record.data['cups']);
		hostForm.queryById("netcards").setValue(record.data['netcards']);
		hostForm.queryById("memory").setValue(record.data['memory']);
		hostForm.queryById("fmemoryunit").setValue(record.data['memoryunit']);
		hostForm.queryById("storage").setValue(record.data['storage']);
		hostForm.queryById("fstorageunit").setValue(record.data['storageunit']);
		hostForm.queryById("hostDesc").setValue(record.data['hostDesc']);
		hostForm.queryById("hostIp").setValue(record.data['hostIp']);
		
	},
	editHostConfig:function(){
		var record= Ext.getCmp("hostConfigGrid").getSelectionModel().getLastSelected();
		if(record){
			var hostConfigWin = Ext.getCmp("hostConfigWin");
			hostConfigWin.setTitle("查看主机详细"  );
			hostConfigWin.show();
		}
	},
	closeHostWin:function(){
		Ext.getCmp("hostConfigWin").hide();
	},
	submitForm:function(){
		var me = this;
		if( this.getForm().isValid() ){
			var result = Ext.getCmp("auditResult").getValue();
			var opinion = Ext.getCmp("auditOpinion").getValue();
			var data = {};
			data['stepId'] = me.objId ;
			data['result'] = result ;
			data['opinion'] = opinion ;
	    	var dataSet = new DataSet(this.dataSetHandler,"_save_dataset");
	    	dataSet.setHandlerMethod(this.saveMethod);
	    	dataSet.newRecord();
	    	Ext.iterate(data,function(name,value){
	    		dataSet.setValue(name,value);
	    	});
	    	dataSet.execute(function(result){
	    		if(result.getStatus()=="200"){
	    			Pearlsen.Utils.showSuccessMsg('保存成功');
	    			GlobalEvent.fireEvent(me.moduleName+"_refresh_list");
	    			me.close();
	    			return;
	    		}else{
	    			Pearlsen.Utils.showErrorMsg('保存失败,原因:'+result.message);
	    			return ;
	    		}
	    	});
		}else{
			Pearlsen.Utils.showErrorMsg("请检查主机名或者审批信息是否填写");
		}
	},
	submitApply:function(){
		var me = this;
		if( this.getForm().isValid() ){
			Ext.MessageBox.confirm('提示', '您确定要提交吗?',function(btn){
				if(btn=='yes'){
					var result = Ext.getCmp("auditResult").getValue();
					var opinion = Ext.getCmp("auditOpinion").getValue();
					var data = {};
					data['stepId'] = me.objId ;
					data['result'] = result ;
					data['opinion'] = opinion ;
			    	var dataSet = new DataSet(me.dataSetHandler,"_save_dataset");
			    	dataSet.setHandlerMethod("submitApply");
			    	dataSet.newRecord();
			    	Ext.iterate(data,function(name,value){
			    		dataSet.setValue(name,value);
			    	});
			    	dataSet.execute(function(result){
			    		if(result.getStatus()=="200"){
			    			Pearlsen.Utils.showSuccessMsg('提交成功');
			    			GlobalEvent.fireEvent(me.moduleName+"_refresh_list");
			    			me.close();
			    			return ;
			    		}else{
			    			Pearlsen.Utils.showErrorMsg('提交失败,原因:'+result.message);
			    			return ;
			    		}
			    	});
				}
			});
	    	
		}else{
			Pearlsen.Utils.showErrorMsg("请检查主机名或者审批信息是否填写");
		}
	},
	loadForm:function(){
		//加载资源申请表单
		 var query = new Query("ResApplyQueryHandler","_load_dataset");
		 query.setHandlerMethod("getEntity");		 
		 query.setURL('/query.asp');
		 query.addCondition("objId", this.applyId);
		 query.setCompletedFun(this.afterloadApplyForm);
		 query.setCompletedFunScope(this);
		 query.load();
		 //加载资源配置审批表单
		 var query = new Query(this.queryHandler,"_load_dataset");
		 query.setHandlerMethod("getEntity");		 
		 query.setURL('/query.asp');
		 query.addCondition("objId", this.objId);
		 query.setCompletedFun(this.afterloadForm);
		 query.setCompletedFunScope(this);
		 query.load();		 
		 //加载审批记录
		var auditLogStore = Ext.getCmp("auditLogGrid").getStore();
  		var condition=new Condition("applyId",this.applyId);
  		auditLogStore.clearCondition();
  		auditLogStore.addCondition(condition);
  		auditLogStore.load();
	},
	afterloadApplyForm:function(success,dataset,response, opts){
		if(success){
			if( dataset && !Ext.isEmpty(dataset.record)){
				var record = dataset.record[0];
				Ext.getCmp("resApplyForm").getForm().setValues(record);
				var hostGridStore = Ext.getCmp("hostConfigGrid").getStore();
				if(	Ext.isArray(record.hostList) ){
					hostGridStore.loadData(record.hostList);
				}
			}
		}else{
			
		}
	},
	afterloadForm:function(success,dataset,response, opts){
		if(success){
			if( dataset && !Ext.isEmpty(dataset.record)){
				var record = dataset.record[0];
				Ext.getCmp("auditResult").setValue(record['result']);
				Ext.getCmp("auditOpinion").setValue(record['opinion']);
			}
		}else{
			
		}
	},
	renderAuditGrid:function(value,metaData,record,rowIndex,colIndex,store,view){
		var status =['审批不通过','审批通过','执行完成','执行失败'];
		return status[value];
	},
	/**
	 * 资源使用情况查询
	 */
	queryRes:function(){
		var startDate = Ext.getCmp("startDate").getRawValue();
		var endDate = Ext.getCmp("endDate").getRawValue();
		if( !Ext.isEmpty(startDate) && !Ext.isEmpty(endDate)  ){
			var win = Ext.getCmp("resqueyWin");
			win.show();
			var url = Pls.Webpath +"/pages/rms/resgantt/ResGantt.jsp?startDate={0}&endDate={1}";
			url = url.format(startDate,endDate);
			document.getElementById("framegtt").src=url;
		}
	}
	
	
});